if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (argc >= 2)
- {
- rootdir = g_file_new_for_path (argv[1]);
- }
- else
- {
- if (!ot_admin_get_sysroot_from_proc_cmdline (&rootdir, cancellable, error))
- goto out;
- if (rootdir == NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "No ostree= kernel argument found");
- goto out;
- }
- }
+ rootdir = g_file_new_for_path (argv[1]);
if (!ostree_run_triggers_in_root (rootdir, cancellable, error))
goto out;
}
gboolean
-ot_admin_get_sysroot_from_proc_cmdline (GFile **out_deploy_target,
- GCancellable *cancellable,
- GError **error)
+ot_admin_get_default_ostree_dir (GFile **out_ostree_dir,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
- gs_unref_object GFile *proc_cmdline = g_file_new_for_path ("/proc/cmdline");
- gs_unref_object GFile *ret_deploy_target = NULL;
- gs_free char *contents = NULL;
- gsize contents_len;
- char **cmdline_argv = NULL;
- char **iter;
-
- if (!g_file_load_contents (proc_cmdline, cancellable, &contents, &contents_len, NULL,
- error))
- goto out;
+ gs_unref_object GFile *possible_ostree_dir = NULL;
+ gs_unref_object GFile *ret_ostree_dir = NULL;
- cmdline_argv = g_strsplit (contents, " ", -1);
-
- for (iter = cmdline_argv; *iter; iter++)
+ if (ret_ostree_dir == NULL)
{
- const char *arg = *iter;
- if (strncmp (arg, "ostree=", 7) == 0)
- {
- gs_free char *subpath = g_strdup (arg + 7);
- gs_unref_object GFile *deploydir = g_file_new_for_path ("/sysroot/ostree/deploy");
- ret_deploy_target = g_file_resolve_relative_path (deploydir, subpath);
- break;
- }
+ g_clear_object (&possible_ostree_dir);
+ possible_ostree_dir = g_file_new_for_path ("/sysroot/ostree");
+ if (g_file_query_exists (possible_ostree_dir, NULL))
+ ret_ostree_dir = g_object_ref (possible_ostree_dir);
+ }
+ if (ret_ostree_dir == NULL)
+ {
+ g_clear_object (&possible_ostree_dir);
+ possible_ostree_dir = g_file_new_for_path ("/ostree");
+ if (g_file_query_exists (possible_ostree_dir, NULL))
+ ret_ostree_dir = g_object_ref (possible_ostree_dir);
}
ret = TRUE;
- ot_transfer_out_value (out_deploy_target, &ret_deploy_target);
- out:
- g_strfreev (cmdline_argv);
+ ot_transfer_out_value (out_ostree_dir, &ret_ostree_dir);
return ret;
}
#include "ot-builtins.h"
#include "ot-admin-builtins.h"
+#include "ot-admin-functions.h"
#include "ot-main.h"
#include "ostree.h"
#include "ostree-repo-file.h"
#include <glib/gi18n.h>
-static char *opt_ostree_dir = "/ostree";
+static char *opt_ostree_dir = NULL;
static char *opt_boot_dir = "/boot";
static GOptionEntry options[] = {
goto out;
}
- ostree_dir = g_file_new_for_path (opt_ostree_dir);
+ if (opt_ostree_dir != NULL)
+ {
+ ostree_dir = g_file_new_for_path (opt_ostree_dir);
+ }
+ else
+ {
+ if (!ot_admin_get_default_ostree_dir (&ostree_dir, cancellable, error))
+ goto out;
+ }
boot_dir = g_file_new_for_path (opt_boot_dir);
ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv);